package com.rerun.common.config;

import com.rerun.common.quartz.QuartzManager;
import com.rerun.common.quartz.QuartzManagerCenter;
import com.rerun.mapper.quartz.SchedulerInstanceMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;

import javax.annotation.Resource;

/**
 * The type Quartz config.
 *
 * @author dax.
 * @version v1.0
 * @since 2017 /10/24 13:14
 */
@Configuration
public class QuartzConfig {
    private static final Logger log = LoggerFactory.getLogger("QUARTZ");
    @Resource
    private SchedulerFactoryBean schedulerFactoryBean;
    @Resource
    private SchedulerInstanceMapper schedulerInstanceMapper;

    /**
     * 初始化 quartz 管理中心.
     *
     * @return the quartz manager
     */
    @Bean
    public QuartzManager quartzManager() {
        QuartzManagerCenter quartzManager = new QuartzManagerCenter();
        quartzManager.setScheduler(schedulerFactoryBean.getScheduler());
        quartzManager.setSchedulerInstanceMapper(schedulerInstanceMapper);
        log.info(" quartzManager has been initialized");
        return quartzManager;
    }
}
